# -*- coding: utf-8 -*-
# @description: 
# @File  : server.py
# @Time  :2020-04-05 10:39:25
# @Author:selfeasy
# @Email :gm_selfeasy@163.com
from werkzeug.wrappers import Request, Response
from werkzeug.routing import Map, Rule
from werkzeug.exceptions import NotFound, BadRequest
from utils import url_map
import rules





def app(env, start_response):
    request = Request(env)
    adapter = url_map.bind_to_environ(env)
    try:
        endpoint , values = adapter.match()
        resp = getattr(rules, endpoint)(request, **values)
        print(resp)
    except (NotFound, BadRequest) as e:
        resp = Response('Uncatched Error', status=500)
    return resp(env, start_response)
    
